package org.apache.jsp.procesa;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import java.io.*;
import java.util.*;
import beans.BeanLugares;
import mapping.ElementoMapa;
import mapping.LugarInteres;
import mapping.Telefono;

public final class proc_005fformmodlugar_jsp extends org.apache.jasper.runtime.HttpJspBase
    implements org.apache.jasper.runtime.JspSourceDependent {

  private static final JspFactory _jspxFactory = JspFactory.getDefaultFactory();

  private static java.util.List _jspx_dependants;

  private javax.el.ExpressionFactory _el_expressionfactory;
  private org.apache.AnnotationProcessor _jsp_annotationprocessor;

  public Object getDependants() {
    return _jspx_dependants;
  }

  public void _jspInit() {
    _el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();
    _jsp_annotationprocessor = (org.apache.AnnotationProcessor) getServletConfig().getServletContext().getAttribute(org.apache.AnnotationProcessor.class.getName());
  }

  public void _jspDestroy() {
  }

  public void _jspService(HttpServletRequest request, HttpServletResponse response)
        throws java.io.IOException, ServletException {

    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;


    try {
      response.setContentType("text/html; charset=UTF-8");
      pageContext = _jspxFactory.getPageContext(this, request, response,
      			"../error/errorpage.jsp", true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      out.write('\n');
      out.write('\n');
      out.write('\n');
      beans.BeanLugares mybean = null;
      synchronized (_jspx_page_context) {
        mybean = (beans.BeanLugares) _jspx_page_context.getAttribute("mybean", PageContext.PAGE_SCOPE);
        if (mybean == null){
          mybean = new beans.BeanLugares();
          _jspx_page_context.setAttribute("mybean", mybean, PageContext.PAGE_SCOPE);
        }
      }
      out.write('\n');

	String paramIdLugar = request.getParameter("id_lugar");
	mybean.conectar();
	LugarInteres li = mybean.getLugarById(Integer.parseInt(paramIdLugar));
	int id_lugar = li.getId_elem_mapa();

      out.write("\n");
      out.write("<div id=\"form_mod_lugar\">\t\n");
      out.write("\t<form id=\"formmodlugar\" action=\"#\" onsubmit=\"return false\" method=\"post\" accept-charset=\"UTF-8\">\n");
      out.write("\t<fieldset>\n");
      out.write("\t<legend>Datos de lugar favorito</legend>\n");
      out.write("\t<!-- este campo sera oculto -->\n");
      out.write("\t\t<div id=\"contentformmodlugar\">\n");
      out.write("\t\t\t<div>\n");
      out.write("\t\t\t\t<input type=\"hidden\" name=\"id_lugar\" id=\"id_lugar\" value=\"");
      out.print(id_lugar);
      out.write("\"/>\n");
      out.write("\t\t\t\t<label>Coordenadas</label>\n");
      out.write("\t\t\t\t<input type=\"text\" name=\"latitud\" value=\"");
      out.print(li.getLatitud());
      out.write("\" id=\"latitud\" readonly=\"readonly\"/>\n");
      out.write("\t\t\t\t<input type=\"text\" name=\"longitud\" value=\"");
      out.print(li.getLongitud());
      out.write("\" id=\"longitud\" readonly=\"readonly\"/>\n");
      out.write("\t\t\t</div>\n");
      out.write("\t\t\t<div id=\"itnomlugar\">\n");
      out.write("\t\t\t\t<label for=\"nomlugar\">Nombre<sup>*</sup></label>\n");
      out.write("\t\t\t\t<input type=\"text\" name=\"nomlugar\" id=\"nomlugar\" value=\"");
      out.print(li.getNombre());
      out.write("\"\n");
      out.write("\t\t\t\t\tmaxlength=\"100\" size=\"35\" title=\"Introduzca el nombre del lugar\"/>\n");
      out.write("\t\t\t</div><!-- fin div id=\"itnomlugar\" -->\n");
      out.write("\t\t\t<div id=\"seltipolugar\">\n");
      out.write("\t\t\t\t<label for=\"tipo_nuevo_lugar\">Tipo</label>\n");
      out.write("\t\t\t\t<select id=\"tipo_nuevo_lugar\" name=\"tipo_nuevo_lugar\" size=\"1\" title=\"Selecciona el tipo de lugar\">\n");
      out.write("\t\t\t\t\t");
	
					List listaTipoLugares = mybean.getTipoLugares();
					Iterator it = listaTipoLugares.iterator();			
					while(it.hasNext()){
						String [] valorTipo = ((String) it.next()).split(",");
						if(!valorTipo[1].equalsIgnoreCase(li.getTipo_elem_mapa())){
      out.write("\n");
      out.write("\t\t\t\t\t\t\t<option value = \"");
      out.print(valorTipo[0]);
      out.write('"');
      out.write('>');
      out.print(valorTipo[1]);
      out.write("</option>\n");
      out.write("\t\t\t\t\t\t");
}else{
      out.write("\n");
      out.write("\t\t\t\t\t\t\t<option value = \"");
      out.print(valorTipo[0]);
      out.write("\" selected=\"selected\">");
      out.print(valorTipo[1]);
      out.write("</option>\n");
      out.write("\t\t\t\t\t\t");
}
						} // fin while
						
      out.write("\n");
      out.write("\t\t\t\t</select>\n");
      out.write("\t\t\t</div><!-- fin div id=\"seltipolugar\" -->\n");
      out.write("\t\t\t");

			String direcc = "";
			if(li.getDireccion()!=null && li.getDireccion().trim().length() != 0)
				direcc =li.getDireccion();
			
      out.write("\n");
      out.write("\t\t\t<div id=\"itdirecclugar\">\n");
      out.write("\t\t\t\t<label for=\"direcclugar\">Direcci&oacute;n</label>\n");
      out.write("\t\t\t\t<input type=\"text\" id=\"direcclugar\" name=\"direcclugar\" value=\"");
      out.print(direcc);
      out.write("\" maxlength=\"100\" size=\"50\" title=\"Introduzca la direcci&oacute;n del lugar\"/>\n");
      out.write("\t\t\t</div>\n");
      out.write("\t\t\t");

			String descr = "";
			if(li.getDescripcion()!=null) {
				descr=li.getDescripcion();
			}
			int longdescr = 255 - descr.length();
			
      out.write("\n");
      out.write("\t\t\t<div id=\"tadescrlugar\" style=\"float:left\">\n");
      out.write("\t\t\t\t<label for=\"descrlugar\">Descripci&oacute;n</label>\n");
      out.write("\t\t\t\t<div id=\"capadescripcionlugar\">\n");
      out.write("\t\t\t\t\t<textarea id=\"descrlugar\" name=\"descrlugar\" rows=\"4\" cols =\"45\" title=\"Introduzca la descripci&oacute;n del lugar\"\n");
      out.write("\t\t\t\t\tonkeyup=\"contarCaracteres(this, event)\">");
      out.print(descr);
      out.write("</textarea>\t\t\t\t\t\n");
      out.write("\t\t\t\t</div>\n");
      out.write("\t\t\t\t<div id=\"capacontador\">\n");
      out.write("\t\t\t\t\t<input id=\"contador\" type=\"text\" size=\"4\" readonly=\"readonly\" value=\"");
      out.print(longdescr);
      out.write("\"/>\n");
      out.write("\t\t\t\t\t<br/><small>Max. 255 caracteres</small>\n");
      out.write("\t\t\t\t\t<p id=\"limitechar\"></p>\n");
      out.write("\t\t\t\t</div>\n");
      out.write("\t\t\t</div><!--fin  div id=\"tadescrlugar\" -->\t\n");
      out.write("\t\t\t\n");
      out.write("\t\t\t<div style=\"float:left; width: 50%\">\n");
      out.write("\t\t\n");
      out.write("\t\t\t<h3>Tel&eacute;fonos</h3>\n");
      out.write("\t\t\t");

				List tfnosLugar = li.getTfnos();
				Iterator it2 = tfnosLugar.iterator();
				// contador del n� de tfnos
				int numTfnos = 1;
				// indice para contar los n� de tfno 
				int i=1;
				if(!tfnosLugar.isEmpty())
				numTfnos = tfnosLugar.size(); 
			
      out.write("\n");
      out.write("\t\t\t<div id=\"formocultos\">\n");
      out.write("\t\t\t\t<input type=\"hidden\" id=\"numMaxTfnos\" name=\"numMaxTfnos\" value=\"");
      out.print(numTfnos);
      out.write("\" size=\"2\"/>\n");
      out.write("\t\t\t\t<input type=\"hidden\" id=\"numActualTfnos\" name=\"numActualTfnos\" value=\"");
      out.print(numTfnos);
      out.write("\" size=\"2\"/>\n");
      out.write("\t\t\t\t<input type=\"hidden\" id=\"tfnosElim\" name=\"tfnosElim\" value=\"\"/>\n");
      out.write("\t\t\t</div>\n");
      out.write("\t\t\t\n");
      out.write("\t\t\t<div id=\"listatfnos\">\n");
      out.write("\t\t\t\t<div id=\"btntelefonos\">\n");
      out.write("\t\t\t\t\t<button class=\"mybtn\" onmouseover=\"goLite(this)\" onmouseout=\"goDim(this)\"\n");
      out.write("\t\t\t\t\tonclick=\"anadirTfno()\" title=\"A�adir otro telefono\">+</button>\n");
      out.write("\t\t\t\t\t<button id=\"btnborrtfno\" class=\"mybtn\" onmouseover=\"goLite(this)\" onmouseout=\"goDim(this)\"\n");
      out.write("\t\t\t\t\tonclick=\"quitarTfno()\" title=\"Eliminar telefono\">-</button>\n");
      out.write("\t\t\t\t</div>\n");
      out.write("\t\t\t\n");
      out.write("\t\t\t\t");

				//Si NO hay tfnos dejamos un unico campo de tfno vacio
				if(!it2.hasNext()){
				
      out.write("\n");
      out.write("\t\t\t\t<div class=\"divtfno\" id=\"divtfno");
      out.print(i);
      out.write("\">\n");
      out.write("\t\t\t\t\t<input type=\"hidden\" id=\"idtfno");
      out.print(i);
      out.write("\" name=\"idtfno");
      out.print(i);
      out.write("\" value=\"0\" size=\"2\"/>\n");
      out.write("\t\t\t\t\t<input type=\"checkbox\" id=\"tfnochk_");
      out.print(i);
      out.write("\" name=\"tfnochk_");
      out.print(i);
      out.write("\" class=\"chkbox\"/>\n");
      out.write("\t\t\t\t\t<input type=\"text\" id=\"tfno");
      out.print(i);
      out.write("\" name=\"tfno");
      out.print(i);
      out.write("\" value=\"\" maxlength=\"45\" title=\"Introduzca telefono\"/>\n");
      out.write("\t\t\t\t</div>\t\t\n");
      out.write("\t\t\t\t");

					//E.O.C. mostramos tantos campos de tfno como numeros haya para un lugar
					} else{
					 	boolean primeraIter = true;
						while(it2.hasNext()){
							Telefono tfno = (Telefono) it2.next();
							String numtfno = tfno.getTelefono();
				
      out.write("\n");
      out.write("\t\t\t\t<div class=\"divtfno\" id=\"divtfno");
      out.print(i);
      out.write("\">\n");
      out.write("\t\t\t\t\t<input type=\"hidden\" id=\"idtfno");
      out.print(i);
      out.write("\" name=\"idtfno");
      out.print(i);
      out.write("\" value=\"");
      out.print(tfno.getId_telefono());
      out.write("\" size=\"2\">\n");
      out.write("\t\t\t\t\t<input type=\"checkbox\" id=\"tfnochk_");
      out.print(i);
      out.write("\" name=\"tfnochk_");
      out.print(i);
      out.write("\" class=\"chkbox\">\n");
      out.write("\t\t\t\t\t<input type=\"text\" id=\"tfno");
      out.print(i);
      out.write("\" name=\"tfno");
      out.print(i);
      out.write("\" value=\"");
      out.print(numtfno);
      out.write("\" maxlength=\"45\" title=\"Introduzca telefono\">\n");
      out.write("\t\t\t\t</div>\n");
      out.write("\t\t\t\t");

						i++;
						}//fin while
					}//fin else
				
      out.write("\n");
      out.write("\t\t\t</div><!-- div id=\"listatfnos\" -->\n");
      out.write("\t\t\n");
      out.write("\t\t\t</div><!-- <div style=\"float:left; width: 50%\"> -->\n");
      out.write("\t\t</div><!-- fin <div id=\"contentformmodlugar\"> -->\n");
      out.write("\t\t<!-- Aqui se pone la info al admin de como ha ido la operacion -->\n");
      out.write("\t</form>\t\n");
      out.write("</div><!--div id=\"form_mod_lugar\"-->\n");
      out.write("<div class=\"centrado\">\n");
      out.write("\t<button class=\"mybtn\" onmouseover=\"goLite(this)\" onmouseout=\"goDim(this)\"\n");
      out.write("\tonclick=\"guardaLugar(");
      out.print(id_lugar);
      out.write(")\" title=\"Guardar nuevo lugar\">Guardar</button>\n");
      out.write("\t<button class=\"mybtn\" onmouseover=\"goLite(this)\" onmouseout=\"goDim(this)\"\n");
      out.write("\tonclick=\"Effect.SlideUp($('modlugar'))\" title=\"Cancelar\">Cancelar</button>\n");
      out.write("</div>\n");
      out.write("</fieldset>\n");

	mybean.desconectar();

    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)){
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          try { out.clearBuffer(); } catch (java.io.IOException e) {}
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
      }
    } finally {
      _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
}
